package com.metaera.app.ui.adapters;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.SearchResultResponse;
import com.metaera.app.ui.activities.UserProfileActivity;
import com.metaera.app.utils.image.GlideApp;

import androidx.annotation.NonNull;

public class SearchResultColumnAdapter extends BaseQuickAdapter<SearchResultResponse, BaseViewHolder> {

    public SearchResultColumnAdapter() {
        super(R.layout.item_search_column_type);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            context.startActivity(UserProfileActivity.newIntent(context, getItem(position).getAuthor_id()));
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, SearchResultResponse item) {

        ImageView ivAvatar = holder.getView(R.id.iv_avatar);


        holder.setText(R.id.tv_name, item.getNickname())
                .setText(R.id.tv_introduction, item.getDesc());

        GlideApp.with(ivAvatar)
                .load(item.getAvatar_img())
                .avatar()
                .into(ivAvatar);
    }

}
